package com.example.mywanandroid.project.business;
import com.example.mywanandroid.util.HttpUtil;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class GetData {
    public static void getProjectTitleData(final GetProjectTitleCallBack callBack) {
        String requestArticle = "https://www.wanandroid.com/project/tree/json";
        HttpUtil.sendOkHttpRequest(requestArticle, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                e.printStackTrace();
                //如果获取数据失败传回null
                callBack.onGetProjectTitleData(null);
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String projectTitleData = response.body().string();
                callBack.onGetProjectTitleData(projectTitleData);
            }
        });
    }
    public static void getProjectRecyclerViewData(int currentPage, final GetProjectRecyclerViewCallBack callBack) {
        String request = "https://www.wanandroid.com/project/list/" + currentPage + "/json?cid=294";
        HttpUtil.sendOkHttpRequest(request, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                e.printStackTrace();
                //如果获取失败传回null
                callBack.onGetProjectRecyclerViewCallBack(null);
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String data = response.body().string();
                callBack.onGetProjectRecyclerViewCallBack(data);
            }
        });
    }
}
